Method and apparatus for implementing a white-box cipher

ABSTRACT

An apparatus method and computer media for implementing a white-box block cipher in a software application to create a secure software application having the same functionality as the software application. An implementation of a block cipher is created by: applying an isomorphism between an original finite field representation and a composite field representation, and using this isomorphism to reconstruct the cipher as operations that use only the elements of the composite field, including XOR, linear transformation and S-box; decomposing original S-box into several algebraic steps and merging some of these into other parts of the cipher; in the non-linear step of S-box, implementing the inversion in the original finite field representation with algorithm in the composite field representation; applying an initial threshold implementation of m input shares and n output shares to generate lookup tables for the non-linear step of S-box; applying further threshold implementations to different steps of the cipher to generate lookup tables. The block cipher is applied to at least a portion of the software application to create the secure software application and thereby increase security of a computing platform executing the secure software application.

FIELD OF THE DISCLOSURE

The present disclosure relates to white-box security implementations and related white-box ciphers that can be applied to SM4 encoding schemes.

BACKGROUND

The term “cryptography” refers to techniques for secure communication in the presence of third parties, sometimes referred to as “adversaries’ or “attackers.” Various protocols that prevent third parties or the public from reading private messages can be constructed. Applications of cryptography include electronic commerce, chip-based payment cards, digital currencies, computer passwords, and content streaming. Modern cryptographic algorithms are designed around computational hardness assumptions, making such algorithms hard to break in practice by any adversary. It is theoretically possible to break such a system, but it preferably is not pragmatic to do so in order to discourage potential attackers.

The “black-box” attack model of cryptography is based on the premise that the internal operation of a cipher and the key it uses are not accessible to an adversary, who only has access to its inputs and outputs. This model underlies the development and design of most modern cryptographic algorithms, including Data Encryption Standard (DES), Advanced Encryption Standard (AES) and many others. However, this premise of black box attack models, i.e. that the internal operations of devices are not accessible to an attacker, does not apply to many real-world security problems.

The “white-box” attack model assumes a greater level of visibility and control by the adversary. The white-box attack model can be applied in many more modern implementations, where the attacker may have full visibility and control of the operation, such as in a mobile phone or personal computer that may have debugging tools or installed malware. This presents a challenge to develop countermeasures to an adversary extracting information such as cryptographic keys or influencing the operation to produce undesired results in the white-box model. As a result, the study of countermeasures to subversion in the white-box model has become increasingly important.

Chow, S., Eisen, P., Johnson, H. and Van Oorschot, P. C., White-box cryptography and an AES implementation, International Workshop on Selected Areas in Cryptography, pp. 250-270, (Springer, Berlin, Heidelberg, August 2002) described countermeasures to white-box attacks and thus sensitized the academic community at large to the idea that countermeasures in the white-box scenario might be feasible. The general idea of a white-box AES implementation is to hide the secret key in the S-Boxes of AES, break AES into several steps and insert secret random bijections to obfuscate every step. To keep the implementation functionally equivalent to AES, the inserted parts will be canceled out in the end. However, AES white-box implementations have been successfully attacked. In 2004, Billet, Gilbert and Ech-Chatbi presented an efficient attack (referred to as the BGE attack) on and AES white-box implementation. The BGE attack extracted the embedded AES key with a work factor of 23³⁰ the attacks, and thus is a pragmatic attack.

Many dedicated white-box implementations are known. Some implement a standard cipher in a white-box attack context and some focus on the designs of various non-standard ciphers which are expected to be secure under white-box attack. Such ciphers are referred to as “white-box ciphers.” However, research on cryptanalysis against white-box implementations has made significant progress. Some attacks are unique to the white-box model, because they require detailed structure for analysis. This includes algebraic attacks such as the BGE attack. Additionally, in some scenarios, a “lifting attack” is possible because the key does need to be determined since the lifted algorithm may be used as an oracle and sources of randomness can be overridden.

“Gray-box” attacks such as DPA (Differential Power Analysis) have been repurposed under the name DCA (Differential Computation Analysis) and could be reassessed for effectiveness in white-box scenarios. For example, the advantage of a simple sharing scheme that increases the number of traces that must be collected for analysis as the power of the number of shares is lost when there is no noise, as is the case in the white-box scenario. Some benefits of these countermeasures are retained. Any well-designed sharing scheme, including a threshold scheme applied for combating leakage due to hardware glitches, provides some advantage since identifying information leakage is made more complex through the hiding of direct correlations.

Due to its prevalence, AES has been the focus of analysis and countermeasures, and several white-box implementations of AES have been published and analyzed in the literature. SM4 is a newer standardized cipher and has not been analyzed much in the white-box context. SM4 is a block cipher used in the Chinese National Standard for Wireless LAN WAPI. The SM4 algorithm was invented by Lu Shuwang and it became a national standard in China (GB/T 32907-2016) in August 2016. The SM4 cipher has a block size of 128 bits. It uses an 8-bit S-box and the key size is 128 bits. The only operations used are 32-bit bitwise XOR, 32-bit circular shifts and S-box applications. Encryption or decryption of one block of data is composed of 32 rounds. Each round updates a quarter (i.e., 32 bits) of the internal state. A non-linear key schedule is used to produce the round keys. Decryption uses the same round keys as for encryption, except that they are in reversed order. The round structure of SM4 has several similarities with AES, including an 8-bit S-box determined by inversion in a finite field followed by linear diffusion between the output of four S-boxes.

The first white-box SM4 implementation was proposed by Xiao, Y.; Lai, X. White-Box Cryptography and a White-Box Implementation of the SMS4 Algorithm; Shanghai Jiaotong University: Shanghai, China, pp. 24-34, 2009. The cipher of Xiao et al. was proved to be unsecure from an attack similar to a BGE attack. Another white-box SM4 implementation was proposed in Shi, Y., Wei, W. and He, Z., Lightweight White-box Symmetric Encryption Algorithm Against Node Capture for WSNs, Sensors, 15(5), pp.11928-11952, 2015. This implementation uses the concept of dual ciphers and a randomly selected nonsingular matrix to construct a functionally equivalent white-box encryption algorithm of SM4. Lin, Tingting, et al. Security Evaluation and Improvement of a White-Box SMS4 Implementation Based on Affine Equivalence Algorithm, The Computer Journal 61.12: 1783-1790, 2018, presented an analysis of this implementation and described how an affine equivalence algorithm could be used to extract the key.

SUMMARY

The implementations described herein are white-box implementations that can be applied to SM4. Techniques are applied in a novel manner to create a practical implementation of fixed-key SM4 resistant to white-box attacks. The techniques include the use of a composite fields made possible by the S-box structure, re-expressing the entire cipher in terms of 4-bit intermediate variables to reduce total table size, exclusive use of lookup-tables, and the application of an (n,n) threshold scheme where shares are generated using other parts of the processing state in the generation of the shares. The white-box SM4 implementations described herein are resistant against known white-box attacks, such as affine equivalence attacks, BGE-like attacks and DCA-like attacks.

One implementation includes a method, apparatus or computer-readable media for implementing a white-box block cipher in a software application to create a secure software application having the same functionality as the software application, the method comprising creating an implementation of a block cipher by:

-   -   applying an isomorphism between an original finite field         representation and a composite field representation, and using         this isomorphism to reconstruct the cipher as operations that         use only the elements of the composite field, including XOR,         linear transformation and S-box; decomposing original S-box into         several algebraic steps and merging some of these into other         parts of the cipher; in the non-linear step of S-box,         implementing the inversion in the original finite field         representation with algorithm in the composite field         representation; applying an initial threshold implementation of         m input shares and n output shares to generate lookup tables for         the non-linear step of S-box; applying further threshold         implementations to different steps of the cipher to generate         lookup tables; and

applying the block cipher to at least a portion of the software application to create the secure software application and thereby increase security of a computing platform executing the secure software application.

BRIEF DESCRIPTION OF THE DRAWING

Implementations of the invention will be described below in connection with the attached drawing in which:

FIG. 1 is a block diagram on one round of an SM4 block cipher in accordance with a disclosed implementation.

FIG. 2 is a block diagram of a byte-wise operation example in SM4 in accordance with a disclosed implementation.

FIG. 3 is a block diagram of a lookup table generated by a threshold implementation in accordance with a disclosed implementation.

FIG. 4 is a block diagram of the processing of one branch of first round in accordance with a disclosed implementation.

FIG. 5 is a block diagram of a lookup table for mask generation in accordance with a disclosed implementation.

FIG. 6 is a block diagram of mask generation based on the lookup table of FIG. 5.

FIG. 7 is a block diagram of a computation step in accordance with a disclosed implementation.

FIG. 8 is a block diagram of a computation step in accordance with a disclosed implementation.

FIG. 9 is a block diagram of a computation step in accordance with a disclosed implementation.

FIG. 10 is a block diagram of a computation step in accordance a the disclosed implementation.

FIG. 11 is a block diagram of a process for creating a T-box in accordance a the disclosed implementation.

FIG. 12 is a block diagram of the lookup tables in accordance with the disclosed implementation.

FIG. 13 is a block diagram of a computation of the first branch of the second round in accordance with a disclosed implementation.

FIG. 14 is a block diagram of mask cancellation data flow in accordance with a disclosed implementation.

FIG. 15 is a block diagram of a computation of the first branch of the third round in accordance with a disclosed implementation.

FIG. 16 is a block diagram of a computation of the addition operation of the first branch of the third round in accordance with a disclosed implementation.

FIG. 17 is a block diagram of a computation of the first branch of the fourth round in accordance with a disclosed implementation.

FIG. 18 is a block diagram of a computation of the addition operation of the first branch of the fourth round in accordance with a disclosed implementation.

FIG. 19 is a block diagram of the changed lookup tables in accordance with a disclosed implementation.

FIG. 20 is a block diagram of the computation for ciphertext recovery in accordance with a disclosed implementation.

FIG. 21 is a block diagram of a “Type II Table” in accordance with a disclosed implementation.

FIG. 22 is a block diagram of a “Type III Table” in accordance with a disclosed implementation.

FIG. 23 is a block diagram of a “Type Iv Table” in accordance with a disclosed implementation.

FIG. 24 is a block diagram of a combined lookup tables for a single column in accordance with a disclosed implementation.

FIG. 25 is a block diagram of a simplified T-box in accordance with a disclosed implementation.

FIG. 26 is a block diagram of 4 T-boxes combined with 8×16 tables in accordance a the disclosed implementation.

FIG. 27 is a schematic diagram of an architecture for performing the function in accordance with a disclosed implementation.

FIG. 28 is a flow chart of a high-level method in accordance with a disclosed implementation.

DETAILED DESCRIPTION

Before describing the novel aspects of the disclosed implementations, SM4 will be described in greater detail. SM4 was selected to be used in the Wired Authentication and Privacy Infrastructure (WAPI) standard, is officially mandated in China and plays an important part in providing data confidentiality for WLAN products. SM4 has a 128-bit key size, a 128-bit block size and a 32-round unbalanced Feistel network structure. Let {X₀, X₁, X₃}∈GF )2³²)⁴be the plaintext, K_(i)∈GF (2³²)⁴,(i=0=0, 1, 2, . . . , 31) be the round keys. The SM4 encryption operation is then shown at 100 in FIG. 1. As shown, the plain text {X₀, X₁, X₂, X₃} is inputted. Then, for i=0, 1, 2, . . . , 31:

$\begin{matrix} {X_{i + 4} = {F\left( {X_{i},X_{i + 1},X_{i + 2},X_{i + 3},K_{i}} \right)}} \\ {= {X_{i} \oplus {\tau \left( {X_{i + 1} \oplus X_{i + 2} \oplus X_{i + 3} \oplus K_{i}} \right)}}} \end{matrix}$

The resulting output the cipher text is:

(Y ₀ ,Y ₁ ,Y ₂ ,Y ₃)=(X₃₅ ,X ₃₄ ,X ₃₃ ,X ₃₂)

Where:

-   -   The transformation τ: GF(2³²)→GF(2³²) is a reversible         substitution. It is composed of a linear transformation L and a         non-linear transformation S and, namely τ(x)=L(S(x)).     -   The linear transformation L is defined as

L(B)=B⊕(B«<2⊕(B«<10)⊕(B«<18)⊕(B«<24) FOR B∈GF2³²).

-   -   The transformation S applies four 8×8 bijective S-Boxes in         parallel:

S(A)=(Sbox(α₀),Sbox(α₁),Sbox(α₂),Sbox(α₃)) for A=(α₀,α₁,α₂,α₃), S(A)∈GF(2⁸)⁴.

-   -   The decryption procedure is identical to encryption procedure,         except that the order in which the round keys are used is         reversed.

Composite fields are often used in implementations of Galois Field arithmetic. A field GF(2^(k)) is a composite field when k is not a prime and can be written as k=mn. The fields GF(2^(k)) and GF((2^(m))^(n)) are isomorphic to each other. With an isomorphism, the elements and the operations can be mapped from one to the other.

For an implementation, the composite field GF(2⁸) is used. The elements are mapped in GF(2⁸) to GF((2⁴)²), where the arithmetic in GF((2⁴)²) is constructed by following field polynomials P₁(x) and P₂(x), both being irreducible:

P ₁(x)=x ² +tx+n, over GF(2⁴)

P ₂(x)=x ⁴ +ux ³ +vx ² +wx+N, over GF(2).

A general element g of GF((2⁴)²) can be represented as a linear polynomial (in Y) over, GF(2⁴), as g=y₁Y⊕y₀, with multiplication modulo polynomial P₁(x). All the coefficients are in the 4-bit subfield GF(2⁴). So the pair (y₁,y₀)represents g in terms of a polynomial basis [Y,1] , where Y is one root of P₁(x).

The isomorphism mappings and the operation representations depend on the field polynomials and different bases. We are free to choose either type of basis at each level. The isomorphism mappings between GF(2⁸) and GF((2⁴)²) can be found in a known manner, such as is taught by Rudra, A., Dubey, P. K., Jutla, C. S., Kumar, V., Rao, J. R. and Rohatgi, P. Efficient Rijndael Encryption Implementation with Composite Field Arithmetic, International Work-shop on Cryptographic Hardware and Embedded Systems pp.171-184. Springer, Berlin, Heidelberg, May, 2001; Paar, C. Efficient VLSI Architectures for Bit-parallel Computation in Galois fields. PhD Thesis, Inst. for Experi-mental Math., Univ. of Essen, 1994; and Wong, M. M., Wong, M. L. D., Hijzin, I. and Nandi, A. K. Composite field GF (((2 2) 2) 2) AES S-Box with Direct Computation in GF (2 4) Inversion, Information Technology in Asia (CITA 11), 2011 7th International Conference on, pp. 1-6. IEEE. The details of a known method for representing the operations, such as multiplication and multiplicative inverse, can be found in Canright, D., 2005, August, A Very Compact S-box for AES, International Workshop on Cryptographic Hardware and Embedded Systems pp. 441-455, Springer, Berlin, Heidelberg, July, 2011.

Threshold Implementations are well known as a side channel attack countermeasure as taught by Nikova, S., Rechberger, C. and Rijmen, V. December, Threshold implementations Against Side-channel Attacks and Glitches, International conference on information and communications security pp. 529-545, Springer, Ber-lin, Heidelberg. Dec, 2006. Such an attack is based on secret sharing and multiparty computation. In a disclosed implementation an (n,n) threshold system, which requires a set of n functions ∫_(i) to compute the outputs of a function ƒ, is used. The set of n outputs of the functions ƒ, are called the output shares.

Let

=ƒ(A,B, . . . ) denote a function. A variable A is split into n shares A_(i) when A=Σ_(i)A_(i). A secure threshold implementation can satisfy three properties:

-   -   Property 1 (Non-completeness). Every function is independent of         at least one share of each of the input variables A, B, . . .

z ₁=ƒ₁(A ₂ ,A ₃ , . . . , A _(n) ,B ₂,B₃ , . . . , B _(n), . . . )

z ₂=ƒ₂(A ₁ ,A ₃ , . . . , A _(n) ,B ₁ ,B ₃ , . . . , B _(n), . . . )

z _(n)=ƒ_(n)(A ₁ ,A ₂ , . . . , A _(n−1) ,. . . , B ₂ , . . . , B _(n−1), . . . )

-   -   Property 2 (Correctness). The sum of the sharing gives the         desired output.

z=Σ_(i)z_(i)=Σ_(i)ƒ_(i).

-   -   Property 3 (Uniformity). If the input shares (A₁, A₂,L,A_(n))         consistent with A are uniformly distributed, and similarly for         B, C, . . . , the output shares consistent with z must be         uniformly distributed.

The number of the input shares and output shares affects the properties of a threshold implementation. For example, the uniformity is not guaranteed if a threshold implementation is applied with three shares for each input x, Y and z, and three output shares to the function F (X,Y,Z)=X+YZ . The details of how to create a threshold implementation for such functions are well-known and not discussed further herein. For example, more details and constructions can be found in Bilgin B, Nikova S, Nikov V, Rijmen V, Stütz G, Threshold implementations of all 3×3 and 4×4 S-Boxes, International Workshop on Cryptographic Hardware and Embedded Systems, 9, pp. 76-91), Springer, Berlin, Heidelberg, September 2012; ]Nikova, S., Rechberger, C. and Rijmen, V. December, Threshold Implementations Against Side-channel Attacks and Glitches, International conference on information and communications security pp. 529-545, Springer, Berlin, Heidelberg. Dec, 2006; Nikova, S., Rijmen, V. and Schläffer, M. Secure Hardware Implementation of Non-linear Functions in the Presence of Glitches, International Conference on Information Security and Cryptology p.p 218-234), Springer, Berlin, Heidelberg, December 2008. The disclosed implementations use TI to indicate a threshold implementation.

Before describing the disclosed implementations in detail, several techniques are discussed below. Chow, S., Eisen, P., Johnson, H. and Van Oorschot, P.C., White-box cryptography and an AES implementation, International Workshop on Selected Areas in Cryptography, pp. 250-270. Springer, Berlin, Heidelberg. August 2002, teaches that the algebraic structure of an S -box can be represented as:

$\begin{matrix} {{S(x)} = {{A_{2} \cdot \left( {{A_{1} \cdot x} \oplus C_{1}} \right)^{- 1}} \oplus {C_{2}.{with}}}} & \; \\ {{A_{1} = \begin{bmatrix} 1 & 0 & 1 & 0 & 0 & 1 & 1 & 1 \\ 0 & 1 & 0 & 0 & 1 & 1 & 1 & 1 \\ 1 & 0 & 0 & 1 & 1 & 1 & 1 & 0 \\ 0 & 0 & 1 & 1 & 1 & 1 & 0 & 1 \\ 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 \\ 1 & 1 & 1 & 1 & 0 & 1 & 0 & 0 \\ 1 & 1 & 1 & 0 & 1 & 0 & 0 & 1 \\ 1 & 1 & 0 & 1 & 0 & 0 & 1 & 1 \end{bmatrix}},{C_{1} = \begin{bmatrix} 1 \\ 1 \\ 0 \\ 0 \\ 1 \\ 0 \\ 1 \\ 1 \end{bmatrix}}} & \; \\ {{A_{2} = \begin{bmatrix} 1 & 1 & 0 & 0 & 1 & 0 & 1 & 1 \\ 1 & 0 & 0 & 1 & 0 & 1 & 1 & 1 \\ 0 & 0 & 1 & 0 & 1 & 1 & 1 & 1 \\ 0 & 1 & 0 & 1 & 1 & 1 & 1 & 0 \\ 1 & 0 & 1 & 1 & 1 & 1 & 0 & 0 \\ 0 & 1 & 1 & 1 & 1 & 0 & 0 & 1 \\ 1 & 1 & 1 & 1 & 0 & 0 & 1 & 0 \\ 1 & 1 & 1 & 0 & 0 & 1 & 0 & 1 \end{bmatrix}},{{C_{2} = \begin{bmatrix} 1 \\ 1 \\ 0 \\ 1 \\ 0 \\ 0 \\ 1 \\ 1 \end{bmatrix}};}} & \; \end{matrix}$

and the underlying irreducible polynomial for GF(2⁸) over GF(2) is:

ƒ(x)=x ⁸ +x ⁷ +x ⁶ +x ⁵ +x ⁴ +x ²+1.

However, applicant has discovered that this does not match with the S-box table of SM4. Therefore, the matrix A₂ and the irreducible polynomial have been modified in a novel manner. Verification shows that following parameters and irreducible polynomial will correctly generate the lookup table for the SM4 S -box:

$\begin{matrix} {A_{1} = {{\begin{bmatrix} 1 & 0 & 1 & 0 & 0 & 1 & 1 & 1 \\ 0 & 1 & 0 & 0 & 1 & 1 & 1 & 1 \\ 1 & 0 & 0 & 1 & 1 & 1 & 1 & 0 \\ 0 & 0 & 1 & 1 & 1 & 1 & 0 & 1 \\ 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 \\ 1 & 1 & 1 & 1 & 0 & 1 & 0 & 0 \\ 1 & 1 & 1 & 0 & 1 & 0 & 0 & 1 \\ 1 & 1 & 0 & 1 & 0 & 0 & 1 & 1 \end{bmatrix}C_{1}} = \begin{bmatrix} 1 \\ 1 \\ 0 \\ 0 \\ 1 \\ 0 \\ 1 \\ 1 \end{bmatrix}}} & \; \\ {{A_{2} = {{\begin{bmatrix} 0 & 1 & 0 & 0 & 1 & 0 & 1 & 1 \\ 1 & 0 & 1 & 1 & 1 & 1 & 0 & 1 \\ 0 & 1 & 0 & 1 & 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0 & 1 & 0 & 0 & 1 \\ 0 & 0 & 1 & 1 & 1 & 0 & 0 & 1 \\ 0 & 1 & 0 & 1 & 1 & 0 & 0 & 1 \\ 1 & 0 & 0 & 1 & 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 \end{bmatrix}C_{2}} = \begin{bmatrix} 1 \\ 1 \\ 0 \\ 1 \\ 0 \\ 0 \\ 1 \\ 1 \end{bmatrix}}};} & \; \end{matrix}$

and the underlying irreducible polynomial for GF(2⁸) over GF(2) is:

ƒ(x)=x ⁸ +x ⁶ +x ⁴ +x ³ +x ² +x+1.

It may be noted that the polynomial is simply the reciprocal polynomial (reversed coefficients), and C₁, A₂ and C₂ are the same, but the matrix A₂ is substantially different.

In each round, four 8-bit S-Boxes are applied in parallel and the linear transformation L can be expressed as a block matrix composed of 8×8 matrices. This allows the entire SM4 operation to be expressed in terms of byte-wide operations. The 32×32 linear transformation L is expressed as a 4×4 block matrix of 8×8 matrices:

$L = \begin{bmatrix} l_{00} & l_{01} & l_{02} & l_{03} \\ l_{10} & l_{11} & l_{12} & l_{13} \\ l_{20} & l_{21} & l_{22} & l_{23} \\ l_{30} & l_{31} & l_{32} & l_{33} \end{bmatrix}$

Thirty-two-bit inputs/outputs and round key in each round are presented as the concatenation of four bytes each:

X _(t) =x _(t0) ∥x _(t1) ∥x _(t2) ∥x _(t3)(t={0, 1, . . . , 35})

K _(r) =k _(r0) ∥k _(r1) ∥k _(r2) ∥k _(r3))r={0, 1, . . . , 31})

The round key can be embedded in the S-boxes: s_(k) _(rj) (x)=S(x⊕k_(rj)). One byte of the output in each round can be calculated as follows:

x _(r+4)j) =x _(rj) ⊕l _(j0) ,S _(k) _(r0) (x _((r+1)0) ⊕x _((r+2)0) ⊕x _((r−3)0))

⊕l _(j1) ,S _(k) _(r1) (x _((r+1)1) ⊕x _((r+2)1) ⊕x _((r+3)1))

⊕l _(j2) ,S _(k) _(r2) (x _((r+1)2) ⊕x _((r+2)2) ⊕x _((r+3)2))

⊕l _(j3) ,S _(k) _(r3) (x _((r+1)3) ⊕x _((r+2)3) ⊕x _((r+3)3))

Where r=0, 1, 2, . . . , 31; j=0, 1, 2, 3.

For example, if the key byte is fixed in the S-box, the first byte of X₄ can be calculated with process shown at 200 in FIG. 2. The parallel four byte-wise operation sequences (respecitively 201, 202, 203, and 204) before the final XOR in FIG. 2 are referred to as four “branches” herein.

Multiplications in GF (2⁴) can be defined with an irreducible polynomial of degree 4 over GF(2). Only three irreducible polynomials with degree 4 exist, of which any one can be used for the definition:

ƒ₁(x)=x ⁴ +x ³ +x ² +x+1,

ƒ₂(x)=x ⁴ +x ³ +x+1,

ƒ₃(x)=x ⁴ +x+1.

The field multiplication “*” is defined as:

$\begin{matrix} {{A*B} = {\left( {a_{3},a_{2},a_{1},a_{0}} \right)*\left( {b_{3},b_{2},b_{1},b_{0}} \right)}} \\ {= {\left( {{a_{3}x^{3}} + {a_{2}x^{2}} + {a_{1}x} + a_{0}} \right)\left( {{b_{3}x^{3}} + {b_{2}x^{2}} + {b_{1}x} + b_{0}} \right){{mod}\left( {f_{i}(x)} \right)}}} \end{matrix}$

The number of input shares and output shares for a threshold implementation may differ. When a threshold implementation of m input shares and n output shares is applied on a function F(X,Y,Z, . . . ) (denoted as TI[F(X,Y,Z,...)]), the following steps generate a lookup table:

-   -   1. Split each possible value of an input x into m shares         randomly when generating the table. The set of shares of input X         is {X₁,X₂, . . . }, where m−1 of them are random values (for         example {X₁,X₂, . . . , X_(m−1)}) generated from a pseudo-random         number generator (PRNG), and the last share is computed by         X_(m)=X⊕X₁⊕X₂⊕L⊕X_(m−1). The same as for Y, Z etc. Note that the         input shares are used only in the table generation, but the         inputs of the lookup table are X,Y,ZK .     -   2. Given the functions F_(i), compute n output shares with:

z₁ = F₁(X₂, X₃, …  , X_(m), Y₂, Y₃, …  , Y_(m), …  ) z₂ = F₂(X₁, X₃, …  , X_(m), Y₁, Y₃, …  , Y_(m), …  ) … z_(n) = F_(n)(X₁, X₂, …  , X_(m − 1), …  , Y₁, Y₂, …  , Y_(m − 1), …  )

As described above, it is assumed that such threshold implementations exist, and TI is used to indicate that a threshold implementation is applied.

Steps 1 and 2 can be repeated for all the possible inputs X,Y,Z, . . . , to obtain corresponding output shares. The lookup table, shown in FIG. 3, is generated based on the inputs and its corresponding output shares. A dotted box is used to denote a lookup table herein.

To provide resistance to existing white-box attacks, such as affine equivalence attacks, BGE attacks, and DCA-like attacks, the disclosed implementations can be created based on the following rules:

-   -   1. The way of applying masks (at least on the S-box) should not         be affine.     -   2. The masks can be data-dependent.     -   3. The structure of the algorithm should be as obscure as         possible.     -   4. The correlations between the outputs of each step in the         white-box SM4 implementation and in the standard SM4 cannot be         used to apply analysis.     -   5. Each mask can be dependent on an earlier mask in an inverted         tree structure.

In the disclosed implementation, each intermediate variable is split into four-bit nibbles. With the operations in SM4, such as XOR, shift, and S-box, being divided into several steps, the 4-bit data as well as masks will be processed, and corresponding lookup tables will be generated. The threshold implementations are used to extend the output space of some lookup tables and produce masks at the same time. An isomorphic map is applied on the 4-bit data in S-box to obscure the inner operation. The whole encryption consists of only lookup tables, other calculations are not required.

In the first round, an example of implementing the first branch of FIG. 2 is described. Other branches can be implemented in a similar manner. As shown in FIG. 4, a threshold implementation TI₁ of 4 shares of each input and 3 output shares is selected and applied to the function F(X,Y)=X*Y to generate the lookup table 500 shown in FIG. 5. Each input is divided into two four-bit nibbles: x₁₀=x₁₀ ⁰∥x₁₀ ¹,x₂₀=x₂₀ ⁰∥x₂₀ ¹,x₃₀=xx₃₀ ⁰∥x₃₀ ¹. Using the lookup table, masks ƒ_(rj) ^((i)) are generated from x₁₀ ⁰ and x₂₀ ⁰, and masks g_(rj) ^((i)) from x₁₀ ¹ and x₂₀ ¹, where r=0,1,K ,31, i=0,1,2,3, j=0,1,2. The data flow is depicted at 600 in FIG. 6, using the same table in both cases.

To compute x₁₀ ⁰⊕x₂₀ ⁰⊕x₃₀ ⁰ and x₁₀ ¹⊕x₂₀ ¹⊕xx₃₀ ¹, the additions are accomplished with several steps. In each step, some masks are canceled out and new masks are added. First, the function F(X,Y,Z)=X⊕X*Y⊕Y⊕Z is used to generate a lookup table. Using the lookup table, we get α_(r) ^((i)) and α′_(r) ^((i)) , where r and i are the same as before. This data flow is depicted at 700 in FIG. 7, where the same table is used twice. Note the table generation is not specific to the variables, but the data flow is shown with the specific variables used in this example.

A threshold implementation of 2 shares of each input and 2 output shares (TI₂) is then selected and applied to the function F(X,Y,Z)=X⊕Y⊕Z to generate a lookup table for TI₂(X⊕Y⊕Z). Using the lookup table, we get b_(r,j) ^((i)) from (α₀ ⁽⁰⁾,x₃₀ ⁰,ƒ_(0.1) ⁽⁰⁾), and b′_(r,j) ^((i)) from (α′₀ ⁽⁰⁾,x₃₀ ¹,g_(0.1) ⁽⁰⁾), where r and i are the same as before, j=0,1. This data flow is shown at 800 in FIG. 8. Next, a threshold implementation of 4 shares of each input and 3 output shares (TI₃) is selected and applied to the function F(X,Y)=X⊕²⊕Y to generate a lookup table for TI₃(X⊕X²⊕Y). Using the lookup table, we get c_(r,j) ^((i)) from (b_(0,1) ⁽⁰⁾,ƒ_(0,2) ⁽⁰⁾), and c′_(r,j) ^((i)) from (b′_(0,1) ⁽⁰⁾,g_(0,2) ⁽⁰⁾), where r and i are the same as before, j=0,1,2. This data flow is shown at 900 in FIG. 9. As a result, we get b_(0,0) ⁽⁰⁾⊕c_(0,0) ⁽⁰⁾⊕c_(0,1) ⁽⁰⁾⊕c_(0,2) ⁽⁰⁾=x₁₀ ⁰⊕x₂₀ ⁰⊕x₃₀ ⁰⊕(b_(0,1) ⁽⁰⁾)² from left-hand data flow, and) b′_(0,0) ⁽⁰⁾⊕c′_(0,0) ⁽⁰⁾⊕c′_(0,1) ⁽⁰⁾⊕c′_(0,2) ⁽⁰⁾=x₁₀ ¹⊕x₂₀ ¹⊕x₃₀ ¹⊕(b_(0,1) ⁽⁰⁾)² from right-hand data flow.

As noted above, the algebraic structure of a fixed-key S-box can be represented as:

S _(k) _(rj) (x)=S(x⊕k _(rj))=A ₂(A ₁ x⊕A ₁ k _(rj) ⊕C ₁)⁻¹ ⊕C ₂.

We compute “y=A₁x” first.

Let $A_{1} = {\begin{bmatrix} 1 & 0 & 1 & 0 & 0 & 1 & 1 & 1 \\ 0 & 1 & 0 & 0 & 1 & 1 & 1 & 1 \\ 1 & 0 & 0 & 1 & 1 & 1 & 1 & 0 \\ 0 & 0 & 1 & 1 & 1 & 1 & 0 & 1 \\ 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 \\ 1 & 1 & 1 & 1 & 0 & 1 & 0 & 0 \\ 1 & 1 & 1 & 0 & 1 & 0 & 0 & 1 \\ 1 & 1 & 0 & 1 & 0 & 0 & 1 & 1 \end{bmatrix} = \begin{bmatrix} A_{00} & A_{01} \\ A_{10} & A_{11} \end{bmatrix}}$ $x = \begin{bmatrix} x_{0} \\ x_{1} \end{bmatrix}$

where A_(ij) is a 4×4 block matrix of A₁, x_(i) is a 4×1 vector.

The multiplication “A₁x ” can be represented as:

${A_{1}x} = {{\begin{bmatrix} A_{00} & A_{01} \\ A_{10} & A_{11} \end{bmatrix}\begin{bmatrix} x_{0} \\ x_{1} \end{bmatrix}} = \begin{bmatrix} {{A_{00}x_{0}} \oplus {A_{01}x_{1}}} \\ {{A_{10}x_{0}} \oplus {A_{11}x_{1}}} \end{bmatrix}}$

Six lookup tables for can be generated for functions:

F ₀(X,Y,Z)=A ₀₀ X⊕A ₀₁ Y⊕A ₀₀ Z,

F ₁(X,Y,Z)=X⊕A ₀₁ Y⊕A ₀₀ Z,

F ₂(X,Y,Z)=X⊕A ₀₁Y⊕A₀₀ Z ²,

G ₀(X,Y,Z)=A ₁₁ X⊕A ₁₀ Y⊕A ₁₀ Z,

G ₁(X,Y,Z)=X⊕A ₁₁ Y⊕A ₁₀ Z,

G ₂(X,Y,Z)=X⊕A ₁₁ Y⊕A ₁₀ Z ²

The data flow 1000 of FIG. 10 shows this computation. From the left-hand data flow we get:

d _(0.3) ⁽⁰⁾ =A ₀₀(x ₁₀ ⁰ ⊕x ₂₀ ⁰ ⊕x ₃₀ ⁰)⊕A ₀₁⊕(x ₁₀ ¹ ⊕x ₂₀ ¹ ⊕x ₃₀ ¹)⊕A ₀₁(b _(0,1) ⁽⁰⁾)² and

d′ _(0,3) ⁽⁰⁾ =A ₁₀(x ₁₀ ⁰ ⊕x ₂₀ ⁰ ⊕x ₃₀ ⁰)⊕A ₁₁⊕(x ₁₀ ¹ ⊕x ₂₀ ¹ ⊕x ₃₀ ¹)⊕A ₁₁(b _(0,1) ⁽⁰⁾)²,

-   -   where the subexpression A₀₀(x₁₀ ⁰⊕x₂₀ ⁰⊕x₃₀ ⁰)⊕A₀₁⊕(x₁₀ ¹⊕x₂₀         ¹⊕x₃₀ ¹) of d₃ is A₀₀x₀⊕A₀₁x₁, and A₀₁(b_(0,1) ⁽⁰⁾)² can be         viewed as a mask; A₁₀(x₁₀ ⁰⊕x₂₀ ⁰⊕x₃₀ ⁰)⊕A₁₁(x₁₀ ¹⊕x₂₀ ¹⊕x₃₀ ¹)         of d′₃ is A₁₀x₀⊕A₀₁x₁, and A₁₁(b_(0,1) ⁽⁰⁾)² can be viewed as a         mask.

The remaining portions of the standard S-box can be computed as:

T _(k) _(rj) (y)=A ₂.(y⊕A ₁ .k _(rj) ⊕C ₁)⁻¹ ⊕C ₂.

Now a T-box can be created using the data flow 1100 shown in FIG. 11. The masked data d_(0,3) ⁽⁰⁾ and d′_(0,3) ⁽⁰⁾ are the inputs of the T-box. To obfuscate the relationship between the inputs and outputs of the T-Box, the lookup table is created with a threshold implementation. However, it is not practical to construct uniform threshold shares for an inverse function with 8-bit input, so an isomorphism is used to map the 8-bit operations into 4-bit operations of a chosen composite field. When the inversion is complete, T⁻¹ will be used to map the values back to the field GF (2⁸). The lookup table T-box is generated for all the possible inputs and corresponding outputs with following steps. In Step 1 of FIG. 11, masks from)d_(0,3) ⁽⁰⁾ and d′_(0,3) ⁽⁰⁾ are cancelled out by computing d_(0,3) ⁽⁰⁾⊕A₀₁(b′_(0,1) ⁽⁰⁾)² and d′_(0,3) ⁽⁰⁾⊕A₁₁(b′_(0,1) ⁽⁰⁾)². We get a y for T_(k) _(rj) (y). In Step 2 of FIG. 11, z=y⊕A₁k₀₀⊕C₁ is computed. In Step 3 of FIG. 11, z⁻¹ is computed in a composite field GF((2⁴)²). Isomorphism mapping T is then used to transform the standard 8-bit value into two 4-bit values γ₀∥γ₁ in a composite field. Applicant has implemented a program to find T and the experiment shows that there are 120 irreducible polynomial P(x) of degree 2, and 128 mappings from (GF(2⁸), ƒ(x)) to (GF((2⁴)²), P(x)) for each P(x). Therefore, there are 15360 candidates for T . Each T is an 8×8 invertible matrix. One is chosen and in Step 4 of FIG. 11, F=(γ₁ ²n+γ₁λ₀τ+γ₀ ²)⁻¹ is computed. In Step 5 of FIG. 11, Fγy₁ and F(γ₁τ+γ₀) are computed as the inverse of γ₀∥γ₁. Since a polynomial basis (Y,1) and P(x)=x²+τx+n was chosen, the inverse of γ₁Y+γ₀ is given by:

(γ₁ Y+γ₀)⁻¹=[Fγ ₁]Y+[F(γ₁τ+γ₀)],

where Y is one root of P(x). We apply threshold implementation (TI₄) of 4 shares of each input and 3 output shares to function Fγ₁+d′₃ and F(γ₁τ+γ₀)+d₃, their outputs shares are (G₀, G₁, G₂) and (N₀,N₁,N₂), respectively. In Step 6 of FIG. 11, let

${T^{\prime} = {{A_{2}T^{- 1}} = \begin{bmatrix} T_{00}^{\prime} & T_{01}^{\prime} \\ T_{10}^{\prime} & T_{11}^{\prime} \end{bmatrix}}},{C_{2} = \begin{bmatrix} {C_{2\text{-}00} \oplus C_{2\text{-}01} \oplus C_{2\text{-}02}} \\ {C_{2\text{-}10} \oplus C_{2\text{-}11} \oplus C_{2\text{-}12}} \end{bmatrix}}$

where T′_(ij) is the 4×4 block matrix of T′, (C₂₋₀₀,C₂₋₀₁,C₂₋₀₂) are three shares of the first 4-bit nibble of C₂, (C₂₋₁₀, C₂₋₁₁,C₂₋₁₂) are three shares of the last 4-bit nibble of C₂. Compute t_(t) ⁽⁰⁾=T′₀₀G_(i)⊕T′₀₁N₀⊕C_(2-0i) and s_(i) ⁽⁰⁾=T′₁₀G_(i)⊕T′₁₁N₀⊕C_(2-1i), where i=0,1,2. The matrix T⁻¹ is used to transform two 4-bit values of the composite field back to a standard 8-bit value; A₂ and C₂ are the linear and constant parts of the affine transformation of SM4, respectively. The result is that we have obtained six masked values (t_(0,0) ⁽⁰⁾,t_(0,1) ⁽⁰⁾,t_(0,2) ⁽⁰⁾,s_(0,0) ⁽⁰⁾,s_(0,1) ⁽⁰⁾,s_(0,2) ⁽⁰⁾) from the first branch. With the same method used in above subsections, we get (t_(0,0) ^((i)),t_(0,1) ^((i)),t_(0,2) ^((i)),s_(0,0) ^((i)),s_(0,1) ^((i)),s_(0,2) ^((i))) (i=1,2,3) for remaining three branches. To compute x₄₀, we multiply l_(0i) with outputs of each branch and add them together:

${x_{00} \oplus {l_{00}\begin{bmatrix} {t_{0}^{(0)} \oplus t_{1}^{(0)} \oplus t_{2}^{(0)}} \\ {s_{0}^{(0)} \oplus s_{1}^{(0)} \oplus s_{2}^{(1)}} \end{bmatrix}} \oplus {l_{01}\begin{bmatrix} {t_{0}^{(1)} \oplus t_{1}^{(1)} \oplus t_{2}^{(1)}} \\ {s_{0}^{(1)} \oplus s_{1}^{(1)} \oplus s_{2}^{(1)}} \end{bmatrix}} \oplus} = {{\quad\begin{bmatrix} x_{00}^{0} \\ x_{00}^{1} \end{bmatrix}\quad} \oplus {\begin{bmatrix} P_{00\text{-}00} & P_{00\text{-}01} \\ P_{00\text{-}10} & P_{00\text{-}11} \end{bmatrix}\begin{bmatrix} {t_{0}^{(0)} \oplus t_{1}^{(0)} \oplus t_{2}^{(0)}} \\ {s_{0}^{(0)} \oplus s_{1}^{(0)} \oplus s_{2}^{(1)}} \end{bmatrix}} \oplus {l_{02}\begin{bmatrix} {t_{0}^{(2)} \oplus t_{1}^{(2)} \oplus t_{2}^{(2)}} \\ {s_{0}^{(2)} \oplus s_{1}^{(2)} \oplus s_{2}^{(2)}} \end{bmatrix}} \oplus {{{l_{03}\begin{bmatrix} {t_{0}^{(3)} \oplus t_{1}^{(3)} \oplus t_{2}^{(3)}} \\ {s_{0}^{(3)} \oplus s_{1}^{(3)} \oplus s_{2}^{(3)}} \end{bmatrix}}\begin{bmatrix} P_{01\text{-}00} & P_{01\text{-}01} \\ P_{01\text{-}10} & P_{01\text{-}11} \end{bmatrix}}\begin{bmatrix} {t_{0}^{(1)} \oplus t_{1}^{(1)} \oplus t_{2}^{(1)}} \\ {s_{0}^{(1)} \oplus s_{1}^{(1)} \oplus s_{2}^{(1)}} \end{bmatrix}} \oplus {\begin{bmatrix} P_{02\text{-}00} & P_{02\text{-}01} \\ P_{02\text{-}10} & P_{02\text{-}11} \end{bmatrix}{\quad{{{\begin{bmatrix} {t_{0}^{(2)} \oplus t_{1}^{(2)} \oplus t_{2}^{(2)}} \\ {s_{0}^{(2)} \oplus s_{1}^{(2)} \oplus s_{2}^{(2)}} \end{bmatrix} \oplus {{\begin{bmatrix} P_{03\text{-}00} & P_{03\text{-}01} \\ P_{03\text{-}10} & P_{03\text{-}11} \end{bmatrix}\begin{bmatrix} {t_{0}^{(3)} \oplus t_{1}^{(3)} \oplus t_{2}^{(3)}} \\ {s_{0}^{(3)} \oplus s_{1}^{(3)} \oplus s_{2}^{(3)}} \end{bmatrix}}\mspace{20mu} {Where}\mspace{14mu} l_{0h}}} = \begin{bmatrix} P_{0h\text{-}00} & P_{0h\text{-}01} \\ P_{0h\text{-}10} & P_{0h\text{-}11} \end{bmatrix}},{P_{0h\text{-}ju}\mspace{14mu} {is}\mspace{14mu} a\mspace{14mu} 4 \times 4\mspace{14mu} {block}\mspace{14mu} {matrix}\text{.}}}}}}$

By adding part of the upper half part of each matrix, we get a masked value of x₄₀ ⁰. We can construct 16 lookup tables to implement this step. This data flow is depicted at 1200 in FIG. 12, where i=1, j=0.

It can be verified that x ₄₀ ⁰=x₄₀ ⁰⊕P₀₃₋₀₁s₂ ⁽³⁾. By adding part of the lower half part of each matrix, the result is a masked value of x₄₀ ¹. We construct another 16 lookup tables to compute x ₄₀ ¹. This data flow is also depicted in FIG. 12, except j=1. One can verify that x ₄₀ ¹=x₄₀ ¹⊕P₀₃₋₁₁s_(0,2) ⁽³⁾.

Let

${l_{1h} = \begin{bmatrix} P_{1h\text{-}00} & P_{1h\text{-}01} \\ P_{1h\text{-}10} & P_{1h\text{-}11} \end{bmatrix}},{l_{2h} = \begin{bmatrix} P_{2h\text{-}00} & P_{2h\text{-}01} \\ P_{2h\text{-}10} & P_{2h\text{-}11} \end{bmatrix}},\text{and}$ $l_{3h} = \begin{bmatrix} P_{3h\text{-}00} & P_{3h\text{-}01} \\ P_{3h\text{-}10} & P_{3h\text{-}11} \end{bmatrix}$

where P_(ih-ju) is a 4×4 block matrix, i=1,2,3; j=0,1; u=0,1.

Other three masked bytes of X₄ are generated in a similar way. At this time, 16 lookup tables are constructed to compute x ₄₁ ⁰,x ₄₁ ¹ x ₄₂ ⁰ x ₄₂ ¹ x ₄₃ ⁰and x ₄₃ ¹ respectively. The data flows are the same as depicted in FIG. 12, except i=1,2,3, j=0,1 for x _(4i) ^(j).

One can verif that x ₄₁ ⁰=x₄₁ ⁰⊕P₁₃₋₀₁s_(0,2) ⁽³⁾, x ₄₁ ¹=x₄₁ ¹⊕P₁₃₋₁₁s_(0,2) ⁽³⁾, x ₄₂ ⁰=x₄₂ ⁰⊕P₂₃₋₀₁s_(0,2) ⁽³⁾, x ₄₂ ¹=x₄₂ ¹⊕P₂₃₋₁₁s_(0.2) ⁽³⁾,x ₄₃ ⁰=x₄₃ ⁰⊕P₃₃₋₀₁s_(0.2) ⁽³⁾ and x ₄₃ ¹=x₄₃ ¹⊕P₃₃₋₁₁s_(0.2) ⁽³⁾.

For a second round the first branch of this round is also used, as shown at 1300 in FIG. 13, as an example. In this branch, all the steps are the same as in first branch of first round, except for the addition operation. Since x ₄₀=(x₄₀ ⁰⊕P₀₃₋₀₁s_(0,299(3)))∥(x₄₀ ¹⊕P₀₃₋₁₁s_(0,2) ⁽³⁾) is a masked data, the masks should be cancelled in the addition operation. The lookup tables are only changed in step3, i.e. use threshold implementation (TI₃) of 4 input shares and 3 output shares to compute F(X,Y,Z)=X⊕(X)²⊕Y⊕P₀₃₋₀₁Z , and G(X,Y,Z)=X⊕(X)²⊕Y⊕P₀₃₋₁₁Z. This data flow is depicted at 1400 in FIG. 14. The result of this round is:

x ₅₀ ⁰ =x ₅₀ ⁰ ⊕P ₀₃₋₀₁ s _(1,2) ⁽³⁾ x ₅₀ ¹ =x ₅₀ ¹ ⊕P ₀₃₋₁₁ s _(1,2) ⁽³⁾ , x ₅₁ ⁰ ⊕P ₁₃₋₀₁ s _(1,2) ⁽³⁾,

x ₅₁ ¹ =x ₅₁ ¹ ⊕P ₁₃₋₁₂ s _(1,2) ⁽³⁾ , x ₅₂ ⁰ =x ₅₂ ⁰ ⊕P ₂₃₋₀₁ s _(1,2) ⁽³⁾ , x ₅₂ ¹ =x ₅₂ ¹ ⊕P ₂₃₋ ₁₁ s _(1,2) ⁽³⁾ , x ₅₃ ⁰ =x ₅₃ ⁰ ⊕P ₃₃₋₀₁ s _(1,2) ⁽³⁾,

x ₅₃ ¹ =x ₅₃ ¹ ⊕P ₃₃₋₁₃ s _(1,2) ⁽³⁾.

FIG. 15, at 1500, illustrates data flow of a first branch of a third round. The first branch of this round is as follows and is shown at 1600 in FIG. 16. Similar to the second round, all steps are the same as in the first branch of the first round, except for the addition operation. Since x ₄₀ and x ₅₀ are masked data, the masks can be cancelled in this part. We only change the lookup tables in step 2, i.e. use threshold implementation (TI₂) of 2 input shares and 2 output shares to compute F(X,Y,Z)=X⊕Y⊕P₀₃ ₀₁z and G(X,Y,Z)=X⊕Y⊕P₀₃₋₁₁Z.

The result of this round is:

x ₆₀ ⁰ =x ₆₀ ⁰ ⊕P ₀₃₋₀₁ s _(2,2) ⁽³⁾ x ₆₀ ¹ =x ₆₀ ¹ ⊕P ₀₃₋₁₁ s _(2,2) ⁽³⁾ , x ₆₁ ⁰ ⊕P ₀₃₋₀₁ s _(2,2) ⁽³⁾,

x ₆₁ ¹ =x ₆₁ ¹ ⊕P ₁₃₋₁₁ s _(2,2) ⁽³⁾ x ₆₂ ⁰ =x ₆₂ ⁰ ⊕P ₂₃₋₀₁ s _(2,2) ⁽³⁾,

x ₆₂ ¹ =x ₆₂ ¹ ⊕P ₂₃₋₁₁ s _(2,2) ⁽³⁾,

x ₆₃ ⁰ =x ₆₃ ⁰ ⊕P ₃₃₋₀₁ s _(2,2) ⁽³⁾,

x ₆₃ ¹ =x ₆₃ ¹ ⊕P ₃₃₋₁₁ s _(2,2) ⁽³⁾.

The processing of the first branch of the fifth round is shown at 1700 of FIG. 17. Similar to the second and third rounds, all steps are the same as in the first branch of the first round, except the Addition operation. Lookup tables generated in previous rounds are reused here, as shown at 1800 of FIG. 18. The result of this round is:

x ₇₀ ⁰ =x ₇₀ ⁰ ⊕P ₀₃₋₀₁ s _(3,2) ⁽³⁾,

x ₇₀ ¹ =x ₇₀ ¹ ⊕P ₀₃₋₁₁ s _(3,2) ⁽³⁾,

x ₇₁ ⁰ =x ₇₁ ⁰ ⊕P ₁₃₋₀₁ s _(3,2) ⁽³⁾,

x ₇₁ ¹ =x ₇₁ ¹ ⊕P ₁₃₋₁₁ s _(3,2) ⁽³⁾,

x ₇₂ ⁰ =x ₇₂ ⁰ ⊕P ₂₃₋₀₁ s _(3,2) ⁽³⁾,

x ₇₂ ¹ =x ₇₂ ¹ ⊕P ₂₃₋₁₁ s _(3,2) ⁽³⁾,

x ₇₃ ⁰ =x ₇₃ ⁰ ⊕P ₃₃₋₀₁ s _(3,2) ⁽³⁾,

x ₇₃ ¹ =x ₇₃ ¹ ⊕P ₃₃₋₁₁ s _(3,2) ⁽³⁾.

For remaining rounds, the data flow is the same as in the fourth round except in Compute X₄₀ and Remaining three bytes of X₄. Since, in the fifth round, all inputs are masked data. The two-input lookup tables in Part V: Compute X₄₀ can be changed to three-input lookup tables to cancel an additional mask, and other lookup tables remain the same. The first nibble is used as an example and FIG. 19 indicates the changed tables and the data flow at 1900. For other nibbles, the lookup table can be changed in a similar manner.

After the last round, masked cipher texts (X ₃₂ ,X ₃₃ ,X ₃₄ ,X ₃₅ ) were obtained, where) X _(r) can be divided into eight 4-bit nibbles: X _(r)=(x _(r0) ⁰∥x _(r0) ⁰)∥(x _(r1) ⁰∥x _(r1) ¹)∥(x _(r2) ⁰∥x _(r2) ¹)∥(x _(r3) ⁰∥x _(r3) ¹), where x _(r0) ⁰=x_(r0) ⁰⊕P₀₃₋₀₁s_(r-4,2) ⁽³⁾, x _(r0) ¹=x_(r1) ⁰⊕P₀₃₋₁₁s_(r-4,2) ⁽³⁾, x _(r1) ⁰=x_(r1) ⁰⊕P₁₃₋₀₁s_(r-4,2) ⁽³⁾, x _(r1) ¹=x_(r1) ¹⊕P₁₃₋₁₁s_(r-4,2) ⁽³⁾, x _(r2) ⁰=x_(r2) ⁰⊕P₂₃₋₀₁s_(r-4,2) ⁽³⁾, x _(r2) ¹=x_(r2) ¹⊕P₂₃₋₁₁s_(r-4,2) ⁽³⁾, x _(r3) ⁰=x_(r3) ⁰⊕P₃₃₋₀₁s_(r-4,2) ⁽³⁾, x _(r3) ¹=x_(r3) ¹⊕P₃₃₋₁₁s_(r-4,2) ⁽³⁾.

Now eight lookup tables can be constructed for eight functions as shown at 2000 of FIG. 20:

F ₀(X,Y)=X⊕P ₀₃₋₀₁ Y, F ₁(X,Y)=X⊕P ₀₃₋₁₁ Y

F ₂(X,Y)=X⊕P ₁₃₋₀₁ Y, F ₃(X,Y)=X⊕P ₁₃₋₁₁ Y F ₄(X,Y)=X⊕P ₂₃₋₀₁ Y,

F ₅(X,Y)=X⊕P ₂₃₋₁₁ Y F ₆(X,Y)=X⊕P ₃₃₋₀₁ Y F ₇(X,Y)=X⊕P ₃₁₋₁₁ Y

The result is the following cipher text:

X ₃₂ =x ₍₃₂₎₀ ⁰ ∥x ₍₃₂₎₀ ¹ ∥x ₍₃₂₎₁ ⁰ ∥x ₍₃₂₎₁ ¹ ∥x ₍₃₂₎₂ ⁰ ∥x ₍₃₂₎₂ ¹ ∥x ₍₃₂₎₃ ⁰ ∥x ₍₃₂₎₃ ¹

X ₃₃ =x ₍₃₃₎₀ ⁰ ∥x ₍₃₃₎₀ ¹ ∥x ₍₃₃₎₁ ⁰ ∥x ₍₃₃₎₁ ¹ ∥x ₍₃₃₎₂ ⁰ ∥x ₍₃₃₎₂ ¹ ∥x ₍₃₃₎₃ ⁰ ∥x ₍₃₃₎₃ ¹ X ₃₄ =x ₍₃₄₎₀ ⁰ ∥x ₍₃₄₎₀ ¹ ∥x ₍₃₄₎₁ ⁰ ∥x ₍₃₄₎₁ ¹ ∥x ₍₃₄₎₂ ⁰ ∥x ₍₃₄₎₂ ¹ ∥x ₍₃₄₎₃ ⁰ ∥x ₍₃₄₎₃ ¹

X ₃₅ =x ₍₃₅₎₀ ⁰ ∥x ₍₃₅₎₀ ¹ ∥x ₍₃₅₎₁ ⁰ ∥x ₍₃₅₎₁ ¹ ∥x ₍₃₅₎₂ ⁰ ∥x ₍₃₅₎₂ ¹ ∥x ₍₃₅₎₃ ⁰ ∥x ₍₃₅₎₃ ¹

One important criterion for any white-box implementation is performance. The performance of the above implementation is evaluated below. As a first step, storage cost of the lookup tables was evaluated through the following algorithm.

For 0≤r≤31:

-   -   In Part I: Generate masks, there is only one lookup table for         all branches and rounds. The storage cost is 2⁸×12 bits.     -   In Part II: Addition operation, there are three lookup tables in         the first round. In the second and third rounds, one additional         lookup table is generated respectively. The five lookup tables         are shared for all the rounds and branches. The storage cost is         2×2¹²×4+1×2¹²×8+1×2⁸×12+1×2¹²×12 bits.

In Part III Compute A₁x, there are six lookup tables for all rounds and all branches. The storage cost is 6×2¹²×4 bits.

In Part IV Create a T-box, since the round key is different for each round, the T-box must be generated in each round and each branch. The storage cost is 4×2¹²×24×32 bits.

In Part V: Compute X₄₀ and Part VI: Remaining three bytes of X₄, there are 32 lookup tables for one branch. After four rounds, eight lookup tables must be added.

The storage cost is (15×2¹²×4+2⁸×4)×8+8×2¹²×4 bits=1.5 MB. As noted above, the implementation has 276 lookup tables. The last two parts have the highest storage requirements. In Part IV: Create T-box, a T-box is generated for each key byte to keep the secret key in the only non-linear component of the algorithm. To reduce the storage requirement, the key byte can be moved from the T-box and embedded into a small lookup table. The effect is that only one T-box will exist for all rounds and all branches. Another way to reduce storage requirements is to use matrix operations instead of lookup tables in Part V: Compute X40 and Part VI: Remaining three bytes of X4. Both methods trade security for performance. The above storage cost analysis was conducted on a PC (CPU E3-1240 v5 @ 3.50 GHz, Memory: 16 GB). The experiment showed that the throughput of the implementation is 119 KB/s.

It is axiomatic that a primary criterion for a block cipher is security. The three main cryptographic system attack models of interest include black-box, grey-box, and white-box attacks. Black-box is a traditional attack model in which an adversary only has access to the inputs and outputs of a cryptosystem. As an official encryption standard, SM4 has good performance in resisting classical attacks on block ciphers such as differential and linear attacks.

“Grey-box” is an attack model where the adversary can use leaked information to deploy side-channel cryptanalysis. Different leaked information can lead to different grey-box attacks. DCA (Differential computation analysis) is a powerful side-channel attack against white-box implementations of a cryptosystem. The main reason that DCA is successful is due to the nonnegligible correlation between the expected values (from the standard cipher specification) and the masked intermediate values (from the white-box implementation), which is caused by the linear imbalances in encodings used in white-box implementation. The disclosed implementation is DCA resistant because when the inputs are uniformly distributed, the outputs from the threshold implementation are uniformly distributed, so that the data correlations between SM4 and its white-box implementation are weakened.

In a white-box attack model, a practical symmetric encryption implementation cannot usually find a strict security proof. Instead of reducing the white-box security into solving a computationally infeasible mathematical problem, security of a white-box implementation is assessed by checking whether it is secure against known attacks. The security of the disclosed implementation against two well-known white-box attacks, the BGE attack and the affine equivalence attack, is evaluated below.

The earliest attack against a white-box implementation beyond grey-box attacks is the BGE attack. This attack was originally constructed to recover the round key of the Chow et al.'s white-box AES implementation. The white-box AES implementation includes several phrases (external input and output encodings are exclusive):

-   -   1. The round key is embedded into the S-box by replacing each         S-box with a T-box:

T _(i,j) ^(r)(x)=S(x⊕k _(i,j) ^(r)),

T _(i,j) ¹⁰(x)=S(x⊕k _(i,j) ¹⁰)⊕k _(i,j-i) ¹¹.

-   -   2. The 32×32 matrix MC representing MixColumns is split into         four 32×8 matrices MC_(i).     -   3. To protect T_(i,j) ^(r)(x), 8×8 affine “mixing” bijection         mb_(i) is inserted before T_(i,j) ^(r)(x) and a 32×32 affine         bijection MB is inserted after MC_(l). Meanwhile, concatenated         non-linear permutations are used to decode/encode 4-bit         input/output, and known as input decoding/output encoding. The         resulting lookup table is named as Type II table and shown in         FIG. 21 at 2100. To cancel the effect of MB, a lookup table         takes care of the inversion. The inverse of MB is pre-multiplied         by the inverse of the appropriate four mix bijections and split         into four submatrices (MB⁻¹)_(i). This lookup table is named         Type III table and is shown at 2200 in FIG. 22.     -   5. Four bytes from one column is processed in parallel with the         previous steps and combined with an XOR operation, and called         Type IV table, as shown in FIG. 23 at 2300.

A BGE attack process is summarized below.

-   -   Phase 1. Combine the lookup tables of four bytes in one column         of one round. The effect of MB and adjacent internal encodings         are canceled out. Other encodings are left and denoted as         P_(i,j) ^(r) and Q_(i,j) ^(r) (2400 in FIG. 24):     -   Phase 2. Remove the non-linear part of the encoding Q_(i,j) ^(r)         (the same as P_(i,j) ^(r)).     -   Phase 3. Retrieve the affine part of encoding Q_(i,j) ^(r) (the         same as P_(i,j) ^(r)) by the affine relation between function         y_(i)(x₀,x₁,x₂,x₃)and y_(j)(x₀,x₁x₂,x₃).     -   Phase 4. During the affine recovery process, the key-dependent         affine mapping {tilde over (P)}_(i,j) ^(r)(x)=P_(i,j) ^(r)(x)⊕k         _(i,j) ^(r) are obtained by using inverse of the S-box to cancel         out the effect of the S-box in the function y_(i)(x₀,x₁x₂,x₃).         This enables the key recovery by k _(i,j) ^(r)=P_(i,j)         ^(r)(x)⊕{tilde over (P)}_(i,j) ^(r)(x).     -   Phase 5. Use the same method to recover the round key bytes of         round r+1.

The two cornerstones of the BGE attack are Phase 2 and Phase 3. The key point of Phase 3 is the existence of the affine relationship between y_(i)(x₀,x₁,x₂,x₃) and y_(j)(x₀,x₁, x₂,x₃). To apply a BGE-like attack on the disclosed implementation, the two phases are checked. Since non-linear encodings are not used in the implementation, Phase 2 can be skipped. For Phase 3, constructing a function set should be considered. The functions are key-dependent, so T-boxes must be included.

Considering the T-box on its own. Neither t_(e)nor s, can be represented as a function of inputs (d, b′,d′). The inputs and outputs of T-box 2500 are shown in FIG. 25. The T-box 2500 of FIG. 25 is simplified by dropping some subscripts without loss of generality. t_(j) and s_(j) (j=0,1,2) are computed with G₀,G₁,G₂,N₀,N₁and N₂, which are outputs from a threshold implementation. Based on the Property 1 of the threshold implementation, each output is independent of at least one share of each of the input variables. In other words, there is no functional relationship exists between the inputs (d, b′, d′) and each of G₀,G₁,G₂,N₀,N₁ and N₂. The functions to compute t_(j) and s_(j) use (G_(i),N_(i)) as inputs, which means that each of t_(j) or s_(j) (j=0,1,2) have no functional relationship with inputs (d, b′, d′). Therefore, any combination of lookup tables which end with the T-box cannot be used to construct function set which have an affine relationship.

Lookup tables that follow the T-box are two sets of 16 tables generated in Part V above. To cancel out the effect of the threshold implementation, we can combine four T-boxes with 8×16tables from four branches as shown at 2600 in FIG. 26. A function set {y_(j)(x₀,x₁,x₂,x₃)|j=0,1,2,3} can be obtained and it is easy to prove the functions of the set have an affine relationship. However, note that x_(i) are 12-bit inputs, which does not match the input size of s⁻¹. Therefore, the effect of S-box in function y_(i)(x₀,x₁,x₂,x₃) cannot be canceled out and the attack fails in Phase 4.

Now a look is taken at Affine equivalence attack resistance. For two S-box s₂ (x) and S₁(x), the purpose of the affine equivalence algorithm is to test if there exists two invertible n×n matrices sand A₁ and A₂, and two n-dimensional vectors α₁ and α₂ such that S₂(x)=A₂S₁[A₁(x)⊕α₁]⊕α₂. Several algorithms are presented to solve the affine equivalence problems in Biryukov, A., De Canniere, C., Braeken, A. et al A Toolbox for Cryptanalysis: Linear and Affine Equivalence Algorithms. Advances in Cryptology-EUROCRYPT 2003, pp. 33-50, Springer, Berlin Heidelberg, May 2003. Usually, non-linear transformations or affine mappings are used to obscure an S-box. Since the Phase 2 in a BGE attack can be used to remove the non-linear part of the transformation and keep the affine part remaining, an obscured S-box (referred to as a T-box herein) can be affinely equivalent to the original S-box. Therefore, an affine equivalence algorithm is an efficient attack against most conventional white-box implementations. However, such affine equivalence attacks do not apply to the disclosed implementation because the sizes of input and output of T-box are 12 bits and 24 bits respectively, which are different than those of standard S-box, and the matrices A₁ and A₂, would be non-square.

Conventional white-box implementations split SM4 into several steps and use affine transformation to protect each step. However, the disclosed implementation described above adopts a different approach. The S-box is split into two steps to thereby obscure the boundary of the S-box and help protect the key when it is embedded in the S-box. Second, the elements and operations in GF(2⁸) are mapped to a composite field GF(2⁴)², which increase the difficulty to identify the original operations. Third, threshold implementation techniques are used that, weaken the correlation between the white-box implementation and standard SM4. These techniques work together to protect the SM4 under BGE-like attacks, affine equivalence attacks and DCA attacks. Table 1 below compares the disclosed implementation conventional implementations. While the disclosed implementation has larger storage requirements, it has good performance on resisting popular white-box attacks.

TABLE 1 A comparation between WB-SM4 implementations Security Performance Affine Size of BGE equivalence lookup Other attack attack DCA tables operations resistance resistance resistance WBSM4 * 149 KB Matrix No Unknown Unknown multi- plication WBSM4 First 144 KB Matrix Unknown No Unknown algorithm ** multi- plication The Disclosed 1.5 MB None Yes Yes Yes Implementation * Xiao, Y.; Lai, X. White-Box Cryptography and a White-Box Implementation of the SMS4 Algorithm; Shanghai Jiaotong University: Shanghai, China, pp. 24-34, 2009. **Shi, Y., Wei, W. and He, Z., lightweight white-box symmetric encryption algorithm against node capture for WSNs. Sen-sors, 15(5), pp. 11928-11952, 2015.

The disclosed implementation is based on a composite field and a threshold implementation. The implementation works on 4-bit nibbles instead of on bytes. The threshold implementation makes the distribution of the masked values uniform and independent of the corresponding unmasked values. The operation in a smaller composite field reduce the size of the lookup tables. The disclosed implementation is resistant against traditional white-box attacks, such as the affine equivalence attacks, the BGE-like attacks and DCA-like attacks.

The above-described implantations may be accomplished by a computer or computing system 2700, as shown in FIG. 27. Computing system 27 can include computing devices 2712 having one or more processors 2714 and one or more memories storing instruction, that when executed by the processors 2714, accomplish the disclosed computations and storage. The computer system can include servers, client computing platforms, and/or external resources 2720, which may be operatively linked via one or more electronic communication links. For example, such electronic communication links may be established, at least in part, via a network such as the Internet and/or other networks. By way of non-limiting example, the computing system may include one or more remote computing devices 2718, including a desktop computer, a laptop computer, a handheld computer, a tablet computing platform, a NetBook, a Smartphone, a gaming console, a server, and/or other computing platforms. The computing devices 2712 may include communication lines, or ports to enable the exchange of information with a network and/or other computing platforms. Memories may include electronic storage devices that may comprise non-transitory storage media that electronically stores information. The electronic storage media of electronic storage may include one or both of system storage that is provided integrally (i.e., substantially non-removable) with computing devices 2712 and/or removable storage that is removably connectable to computing devices 2712 via, for example, a port (e.g., a USB port, a firewire port, etc.) or a drive (e.g., a disk drive, etc.). Electronic storage may include one or more of optically readable storage media (e.g., optical disks, etc.), magnetically readable storage media (e.g., magnetic tape, magnetic hard drive, floppy drive, etc.), electrical charge-based storage media (e.g., EEPROM, RAM, etc.), solid-state storage media (e.g., flash drive, etc.), and/or other electronically readable storage media. Electronic storage may include one or more virtual storage resources (e.g., cloud storage, a virtual private network, and/or other virtual storage resources). Electronic storage may store software algorithms, information determined by processor(s), information received from computing devices 2712, the described data structures, and/or other information and machine-readable instructions 2716 that the processors 2714 to carry out the functions as described herein.

Processor(s) may include one or more of a digital processors, an analog processor, a digital circuit designed to process information, an analog circuit designed to process information, a state machine, and/or other mechanisms for electronically processing information. Processor(s) may be configured to execute modules by software; hardware; firmware; some combination of software, hardware, and/or firmware; and/or other mechanisms for configuring processing capabilities on processor(s). As used herein, the term “module” may refer to any component or set of components that perform a specified functionality attributed to the module. This may include one or more physical processors 2714 during execution of processor readable instructions, the processor readable instructions, circuitry, hardware, storage media, or any other components.

FIG. 28 illustrates a high-level method for implementing a white-box block cipher in a software application to create a secure software application having the same functionality as the software application in accordance with the disclosed implementations. The process can be accomplished by any computing platform, such as the system shown in FIG. 27. At 2802 an isomorphism is applied between an original finite field representation and a composite field representation, and the isomorphism is used to reconstruct the cipher as operations that use only the elements of the composite field, including XOR, linear transformation and S-box. At 2804 the original S-box is decomposed into several algebraic steps and merging some of these into other parts of the cipher. At 2806, in the non-linear step of S-box, the inversion in the original finite field representation is implemented with an algorithm in the composite field representation. At 2808, a threshold implementation of m input shares and n output shares is applied to generate lookup tables for the non-linear step of S-box. At 2810, further threshold implementations are applied to different steps of the resulting cipher to generate lookup tables. At 2812 the resulting block cipher is applied to at least a portion of the software application to create the secure software application and thereby increase security of a computing platform executing the secure software application.

Although the present technology has been described in detail for the purpose of illustration based on what is currently considered to be the most practical and preferred implementations, it is to be understood that such detail is solely for that purpose and that the technology is not limited to the disclosed implementations, but, on the contrary, is intended to cover modifications and equivalent arrangements that are within the spirit and scope of the appended claims. For example, it is to be understood that the present technology contemplates that, to the extent possible, one or more features of any implementation can be combined with one or more features of any other implementation. Further, features may be added or removed from the implementations to correspond to the specific application. 

What is claimed:
 1. A method for implementing a white-box block cipher in a software application to create a secure software application having the same functionality as the software application, the method comprising: creating an implementation of a block cipher by: applying an isomorphism between an original finite field representation and a composite field representation, and using this isomorphism to reconstruct the cipher as operations that use only the elements of the composite field, including XOR, linear transformation and S-box; decomposing original S-box into several algebraic steps and merging some of these into other parts of the cipher; in the non-linear step of S-box, implementing the inversion in the original finite field representation with algorithm in the composite field representation; applying an initial threshold implementation of m input shares and n output shares to generate lookup tables for the non-linear step of S-box; applying further threshold implementations to different steps of the cipher to generate lookup tables; and applying the block cipher to at least a portion of the software application to create the secure software application and thereby increase security of a computing platform executing the secure software application.
 2. The method of claim 1, wherein the original finite field representation comprises an 8-bit element.
 3. The method of claim 1, wherein the composite field representation comprises two 4-bit elements.
 4. The method of claim 1, wherein the isomorphism is constructed from elements in GF(2⁸) to the composite field GF (2⁴)² for the S-box and the threshold implementation is applied to mask the inputs and outputs of the cipher.
 5. The method of claim 1, wherein the initial threshold implementation generates masks and extends outputs of the lookup tables to thereby obfuscate the S-box.
 6. The method of claim 5, wherein each mask is dependent on an earlier mask in an inverted tree structure.
 7. An apparatus for implementing a white-box block cipher in a software application to create a secure software application having the same functionality as the software application, the apparatus comprising: at least one hardware processor; and at least one memory operatively coupled to the processor and storing instucitons thereon that, when executed by the at least one hardware processor, cause the at least one hardware processor to: create an implementation of a block cipher by: applying an isomorphism between an original finite field representation and a composite field representation, and using this isomorphism to reconstruct the cipher as operations that use only the elements of the composite field, including XOR, linear transformation and S-box; decomposing original S-box into several algebraic steps and merging some of these into other parts of the cipher; in the non-linear step of S-box, implementing the inversion in the original finite field representation with algorithm in the composite field representation; applying an initial threshold implementation of m input shares and n output shares to generate lookup tables for the non-linear step of S-box; applying further threshold implementations to different steps of the cipher to generate lookup tables; and applying the block cipher to at least a portion of the software application to create the secure software application and thereby increase security of a computing platform executing the secure software application.
 8. The apparatus of claim 7, wherein the original finite field representation comprises an 8-bit element.
 9. The apparatus of claim 7, wherein the composite field representation comprises two 4-bit elements.
 10. The apparatus of claim 7, wherein the isomorphism is constructed from elements in GF(2⁸) to the composite field GF (2⁴)² for the S-box and the threshold implementation is applied to mask the inputs and outputs of the cipher.
 11. The apparatus of claim 7, wherein the initial threshold implementation generates masks and extends outputs of the lookup tables to thereby obfuscate the S-box.
 12. The apparatus of claim 11, wherein each mask is dependent on an earlier mask in an inverted tree structure.
 13. Non-transitory computer-readable media having instructions stored thereon which, when executed by a processor of a computing platform, cause the computing platform to carry out a method for implementing a white-box block cipher in a software application to create a secure software application having the same functionality as the software application, the method comprising: creating an implementation of a block cipher by: applying an isomorphism between an original finite field representation and a composite field representation, and using this isomorphism to reconstruct the cipher as operations that use only the elements of the composite field, including XOR, linear transformation and S-box; decomposing original S-box into several algebraic steps and merging some of these into other parts of the cipher; in the non-linear step of S-box, implementing the inversion in the original finite field representation with algorithm in the composite field representation; applying an initial threshold implementation of m input shares and n output shares to generate lookup tables for the non-linear step of S-box; applying further threshold implementations to different steps of the cipher to generate lookup tables; and applying the block cipher to at least a portion of the software application to create the secure software application and thereby increase security of a computing platform executing the secure software application.
 14. The method of claim 13, wherein the original finite field representation comprises an 8-bit element.
 15. The method of claim 13, wherein the composite field representation comprises two 4-bit elements.
 16. The method of claim 13, wherein the isomorphism is constructed from elements in GF(2⁸) to the composite field GF (2⁴)² for the S-box and the threshold implementation is applied to mask the inputs and outputs of the cipher.
 17. The method of claim 13, wherein the initial threshold implementation generates masks and extends outputs of the lookup tables to thereby obfuscate the S-box.
 18. The method of claim 17, wherein each mask is dependent on an earlier mask in an inverted tree structure. 